package controller.menus;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import model.memento.MementoManager;

public class RedoMenuItemController implements ActionListener, ChangeListener {

	private final JMenuItem redoItem;
	// UndoManager
	private final MementoManager redoManager;

	public RedoMenuItemController(JMenuItem redoItem, MementoManager redoManager) {
		this.redoItem = redoItem;
		this.redoManager = redoManager;
		this.redoManager.addUndoableEditHappenedEventListener(this);
		this.redoItem.setEnabled(redoManager.canRedo());
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// redo compound action
		redoManager.redo();
	}

	/**
	 * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
	 */
	@Override
	public void stateChanged(ChangeEvent e) {
		redoItem.setEnabled(redoManager.canRedo());
	}
}
